/**
 * Este modulo se encarga de encriptar y desencriptar cadenas de char
 * utilizando el algoritmo DES.
 *
 * @author Bellver Gonzalo, Gross German, Pampliega Juan Martin
 * @version 1.0
 * @file cypher.c
 * @date 03/05/08
 **/


#ifndef __CYPHERADT_H__
#define __CYPHERADT_H__


/*************************/
/* Inclusion de archivos */
/*************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "encrypt.h"
#include "../error/error.h"


/***********************/
/* Definicion de tipos */
/***********************/

typedef struct
{
	unsigned char *msg;
	int len;
} cypherT;


/***************************/
/* Prototipos de Funciones */
/***************************/
/**
 ** Cyphers a message. Returns cypherT with a malloced version of the encripted
 **  message and the leght in bytes. 
 **
 ** @param	msg		Pointer to the message.
 ** @param	len		Message's length.
 ** @param	key		Pointer to the encription key (Must be NULL terminated).
 ** @return			Returns a structure of type cypherT that contains the 
 **					cyphered message and it's length.
 **/
cypherT cypher(void *msg, int len, char *key);


/**
 ** Decyphers a message. Returns cypherT with a malloced version of the decripted
 **  message and the leght in bytes. 
 **
 ** @param	msg		Pointer to the message.
 ** @param	len		Message's length.
 ** @param	key		Pointer to the encription key (Must be NULL terminated).
 ** @return			Returns a structure of type cypherT that contains the 
 **					decyphered message and it's length.
 **/
cypherT decypher(void *msg, int len, char *key);


/**
 ** Cyphers a message. Returns cypherT with a malloced version of the encripted
 **  message and it's lenght in bytes. 
 **
 ** @param	msg		Pointer to the message.
 ** @param	len		Message's length.
 ** @param	key		Pointer to the encription key (Must be NULL terminated).
 ** @return			Returns the cyphered message in the pointer provided and an 
 **					int to show if it ended ok or there was an error.
 **/
int cypher2(char * string, int len, char * key);


/**
 ** Decyphers a message. Returns cypherT with a malloced version of the decripted
 **  message and the leght in bytes. 
 **
 ** @param	msg		Pointer to the message.
 ** @param	len		Message's length.
 ** @param	key		Pointer to the encription key (Must be NULL terminated).
 ** @return			Returns a structure of type cypherT that contains the 
 **					decyphered message and it's length.
 **/
int decypher2(char * string, int len, char * key);

#endif /* __CYPHERADT_H__ */

